package com.autumn.security.constants;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.autumn.common.api.domain.values.IntegerConstantItemValue;

/**
 * 用户状态常量
 * 
 * @author 杨昌国 2018-11-24 22:02:10
 */
public final class UserStatusConstants implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6196790225106421047L;

	/**
	 * 正常
	 */
	public static final int NORMAL = 1;

	/**
	 * 锁定
	 */
	public static final int LOCKING = 2;

	/**
	 * 过期
	 */
	public static final int EXPIRED = 3;

	/**
	 * 未激活
	 */
	public static final int NOT_ACTIVATE = 4;

	private static final Map<Integer, IntegerConstantItemValue> NAME_MAP = new HashMap<>();

	static {
		NAME_MAP.put(NORMAL, new IntegerConstantItemValue(NORMAL, "正常", "处理正常状态"));
		NAME_MAP.put(LOCKING, new IntegerConstantItemValue(LOCKING, "锁定", "处理锁定状态，不可登录"));
		NAME_MAP.put(EXPIRED, new IntegerConstantItemValue(EXPIRED, "过期", "处理过期状态，不可登录"));
		NAME_MAP.put(NOT_ACTIVATE, new IntegerConstantItemValue(NOT_ACTIVATE, "未激活", "处理待激活状态"));
	}

	/**
	 * 是否存在
	 * 
	 * @param value
	 *            值
	 * @return
	 */
	public static boolean exist(Integer value) {
		if (value == null) {
			return false;
		}
		return NAME_MAP.containsKey(value);
	}

	/**
	 * 获取名称
	 * 
	 * @param value
	 *            值
	 * @return
	 */
	public static String getName(Integer value) {
		IntegerConstantItemValue item = NAME_MAP.get(value);
		if (item == null) {
			return "";
		}
		return item.getName();
	}

	/**
	 * 项目集合
	 * 
	 * @return
	 */
	public static Collection<IntegerConstantItemValue> items() {
		return NAME_MAP.values();
	}
}
